package com.example.demo.controller;

import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import org.apache.http.client.ClientProtocolException;

import com.alibaba.fastjson.JSONObject;
import com.example.demo.common.HttpUtils;

import com.example.demo.constants.ResultEnity;
import com.example.demo.entity.BookEntity;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

@RestController
@RequestMapping("/service")
@Api(tags = "用户相关接口文档")
public class ServicesController {
	
	//@RequestMapping("/service/Test")	
	@RequestMapping(value = "/Test", method = RequestMethod.POST)
	@ApiOperation( httpMethod = "POST", value = "添加用户", notes = "增加用户")
	public ResultEnity<BookEntity> Post(@ApiParam(name = "token", value = "token", required = false) @RequestHeader String token) throws IOException {		

	    BookEntity data=new BookEntity();
	    data.setName("三国演义");
	    
	    System.out.println(token);
	    
	    try {
//	    	int z=3/0;
	    	data.setSummary(token);
	    }
	    catch (Exception ex) {
			// TODO: handle exception
	    	return ResultEnity.Error("系统出错误了,错误信息："+ex.getMessage(), null);
	    }
	    
	    return ResultEnity.Success("成功",data); 
	    
		//return result;
	}
	
	@RequestMapping("/service/get")
	@ApiOperation(httpMethod = "GET", value = "服务查询",  notes = "服务查询")
	public ResultEnity<Map<String, Object>> Get(@ApiParam(name = "name", value = "名称", required = true) String name) throws IOException {
		
        String response="";
		
        response=HttpUtils.Get("http://localhost:8080/book/list");
        
        System.out.println(response);
	    
	    Map<String, Object> data=new HashMap<>();
	    data.put("departmentId", "13232323");
	    data.put("departmentName", "产品研发部");
	    
	    ResultEnity<Map<String, Object>> result= ResultEnity.Success("操作成功", data);
	   
	    System.out.println(result);
		
		return result;
	}

}
